28 #ifndef _spoton_pacify_h_ 29 #define _spoton_pacify_h_ 41 size_t n = passphrase.length();
55 m_passphrase_length = 0;
57 for(
size_t i = 0; i < n; i++)
58 if((static_cast<int> (passphrase.at(i)) & 0xc0) != 0x80)
59 m_passphrase_length += 1;
61 if(m_passphrase_length > 0)
62 m_passphrase =
new long int[m_passphrase_length];
72 for(
size_t i = 0, j = 0; i < n; j++)
74 int c =
static_cast<int> (passphrase.at(i++));
81 m_passphrase[j] =
static_cast<long int> (c);
83 else if((c & 0xc0) == 0xc0)
113 m_passphrase[j] =
static_cast<long int> (c);
134 c =
static_cast<int> (passphrase.at(i++));
136 if((c & 0xc0) != 0x80)
152 m_passphrase[j] <<= 6;
153 m_passphrase[j] |=
static_cast<long int> (c & 0x3f);
168 delete []m_passphrase;
171 double evaluate(
void)
const 173 if(!m_passphrase || m_passphrase_length == 0)
178 std::map<long int, int> used;
179 std::map<double, int> classes;
184 for(
int i = 1; i <= 10; i++)
187 for(
size_t i = 0; i < m_passphrase_length; i++)
190 long int c = m_passphrase ? m_passphrase[i] : 0;
194 if(used.end() == used.find(c))
199 rc += std::pow(r, 2);
211 if(classes.end() == classes.find(r - 1.0))
212 classes[r - 1.0] = 0;
214 classes[r - 1.0] += 1;
218 if(c > 127 || last > 127)
219 r = distance(
'\0',
'\0');
221 r = distance(static_cast<char> (c), static_cast<char> (last));
223 rc += std::pow(r, 0.5);
238 for(std::map<double, int>::iterator it = classes.begin();
239 it != classes.end(); i++, it++)
251 if(a + b + c + d == 0.0)
255 double r = std::pow(a, 2) + std::pow(b, 2) + std::pow(c, 3) +
258 rc += 30.0 *
static_cast<double> (m_passphrase_length) /
262 return std::floor(rc + 0.5);
266 long int *m_passphrase;
267 size_t m_passphrase_length;
269 double char_class(
const long int c)
const 271 if(static_cast<long int> (
'0') <= c && c <= static_cast<long int> (
'9'))
273 else if(static_cast<long int> (
'a') <= c &&
274 c <= static_cast<long int> (
'z'))
276 else if(static_cast<long int> (
'A') <= c &&
277 c <= static_cast<long int> (
'Z'))
279 else if(c < (1 << 7))
281 else if(c < (1 << 8))
283 else if(c < (1 << 10))
285 else if(c < (1 << 14))
287 else if(c < (1 << 16))
289 else if(c < (1 << 18))
291 else if(c < (1 << 22))
293 else if(c < (1 << 26))
299 double distance(
const char a,
const char b)
const 306 std::transform(_a_.begin(), _a_.end(), _a_.begin(), ::tolower);
307 std::transform(_b_.begin(), _b_.end(), _b_.begin(), ::tolower);
312 std::map<char, std::pair<double, double> > keys;
313 std::string L1(
"1234567890");
314 std::string L2(
"qwertyuiop");
315 std::string L3(
"asdfghjkl");
316 std::string L4(
"zxcvbnm");
317 std::string _a_b_(_a_ + _b_);
319 for(
size_t i = 0; i < L1.length(); i++)
320 keys[L1[i]] = std::pair<double, double> (static_cast<double> (i), 0.0);
322 for(
size_t i = 0; i < L2.length(); i++)
323 keys[L2[i]] = std::pair<double, double> (static_cast<double> (i) + 0.5,
326 for(
size_t i = 0; i < L3.length(); i++)
327 keys[L3[i]] = std::pair<double, double> (static_cast<double> (i) + 0.75,
330 for(
size_t i = 0; i < L4.length(); i++)
331 keys[L4[i]] = std::pair<double, double> (static_cast<double> (i) + 1.0,
334 for(
size_t i = 0; i < _a_b_.length(); i++)
335 if(keys.end() == keys.find(_a_b_[i]))
338 return std::pow(std::pow(keys[_a_.at(0)].first -
339 keys[_b_.at(0)].first, 2) +
340 std::pow(keys[_a_.at(0)].second -
341 keys[_b_.at(0)].second, 2), 0.5);
Definition: spot-on-pacify.h:36